import program from "commander";
import { VERSION } from "./utils/constants";
//多种功能命令
let actionMap = {
  install: {//配置命令的名字
    alias: 'i',//命令别的名称
    description: 'install template', //命令对应的描述
    examples: [//命令对应的模板
      'zf-cli i',
      'zf-cli install'
    ]
  },
  config: {
    alias: 'c',
    description: 'config .zfclirc',
    examples: [
      'zf-cli config set <k> <v>',
      'zf-cli config get <k>',
      'zf-cli config remove <k>'
    ]
  },
  '*': {
    description: 'not found',
    examples: []
  }
}

Object.keys(actionMap).forEach(action => {
  program.command(action)
    .description(actionMap[action].description)
    .alias(actionMap[action].alias)
    .action(() => {
      //console.log(action)
      //判断一下当前用的是什么操作
      if (action === 'config') {
        //实现更改配置文件
        //console.log(process.argv)//数组
        main(action, process.argv.slice(3));
      } else if (action === 'install') {

      }
      main()
    })
})

function help() {
  // console.log('123')//把example显示出去
  console.log('\r\n  ' + 'how to use command');
  Object.keys(actionMap).forEach(action => {
    actionMap[action].examples.forEach(example => {
      console.log('  - ' + example)
    })
  })
}
program.on('-h', help);
program.on('--help', help);
program.version(VERSION, '-v --version').parse(process.argv);